import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { getProductList } from './DeviceInfo.api';
export const columns: BasicColumn[] = [
    {
        title: '设备编号',
        dataIndex: 'deviceNo'
    },
    {
        title: '设备名称',
        dataIndex: 'deviceName'
    },
    {
        title: '所属产品',
        dataIndex: 'productName'
    },
    {
        title: '设备省市区',
        dataIndex: 'areaCode'
    },
    {
        title: '设备详细地址',
        dataIndex: 'deviceAddress'
    },
    // {
    //     title: '设备方位',
    //     dataIndex: 'deviceLocation'
    // },
    // {
    //     title: '设备通道',
    //     dataIndex: 'channelNumber'
    // },
    {
        title: '设备描述',
        dataIndex: 'deviceRemark'
    },
    {
        title: '设备状态',
        dataIndex: 'deviceStatus',
        customRender: ({ text, record }) => {
            if (record.deviceStatus === 1) {
                return '在线'
            }
            return '离线'
        },
    },
    {
        title: '创建时间',
        dataIndex: 'createTime'
    }
];

export const searchFormSchema: FormSchema[] = [
    {
        label: '所属产品',
        field: 'productId',
        // slot: 'productId',
        component: 'ApiSelect',
        componentProps: {
            api: () => defHttp.get({ url: '/dictCommon/getProductList' }),
            //数值转成String
            numberToString: false,
            //标题字段
            labelField: 'productName',
            //值字段
            valueField: 'productId',
            //请求参数
            params: {},
            //返回结果字段
            resultField: 'records',
        }
    },
    {
        label: '设备编号',
        field: 'deviceNo',
        component: 'Input'
    },
    {
        label: '设备名称',
        field: 'deviceName',
        component: 'Input'
    },
];

export const formSchema: FormSchema[] = [
    // TODO 主键隐藏字段，目前写死为ID
    { label: '', field: 'deviceId', component: 'InputNumber', show: false },
    { label: '', field: 'isEdit', component: 'InputNumber', show: false },
    {
        label: '设备编号',
        field: 'deviceNo',
        component: 'Input',
        rules: [{ required: true, message: "请输入设备编号" }],
        colProps: { span: 11 },
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '所属产品',
        field: 'productId',
        component: 'ApiSelect',
        colProps: { span: 11 },
        componentProps: {
            api: () => defHttp.get({ url: '/dictCommon/getProductList' }),
            //数值转成String
            numberToString: false,
            //标题字段
            labelField: 'productName',
            //值字段
            valueField: 'productId',
            //请求参数
            params: {},
            //返回结果字段
            resultField: 'records',
        },
        rules: [{ required: true, message: "请选择所属产品" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        }
    },
    {
        label: '设备名称',
        field: 'deviceName',
        component: 'Input',
        colProps: { span: 22 },
        rules: [{ required: true, message: "请输入设备名称" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备省市区',
        field: 'jal',
        component: 'JAreaLinkage',
        helpMessage: ['请选择省市区'],
        rules: [{ required: false, message: "请选择省市区" }],
        colProps: {
            span: 11,
        },
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备详细地址',
        field: 'deviceAddress',
        component: 'Input',
        colProps: {
            span: 11,
        },
        rules: [{ required: false, message: "请输入详细地址" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备方位',
        field: 'deviceLocation',
        component: 'JDictSelectTag',
        helpMessage: ['请选择设备方位'],
        componentProps: {
            dictCode: 'device_location',
        },
        colProps: {
            span: 11,
        },
        rules: [{ required: false, message: "请输入设备方位" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备通道',
        field: 'channelNumber',
        component: 'Input',
        colProps: {
            span: 11,
        },
        rules: [{ required: false, message: "请输入设备通道" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备经度',
        field: 'deviceLong',
        component: 'Input',
        componentProps: {
            type: 'number',
        },
        colProps: {
            span: 11,
        },
        rules: [{ required: false, message: "请输入设备经度" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },
    {
        label: '设备纬度',
        field: 'deviceLat',
        component: 'Input',
        componentProps: {
            type: 'number',
        },
        colProps: {
            span: 11,
        },
        rules: [{ required: false, message: "请输入设备纬度" }],
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    },

    {
        label: '设备描述',
        field: 'deviceRemark',
        component: 'Input',
        colProps: {
            span: 22,
        },
        dynamicDisabled: ({ values }) => {
            if (values.isEdit != undefined && values.isEdit == true) {
                return true
            } else {
                return false
            }
        },
    }
];
